/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mx.gnp.dao;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Matersys 86
 */
public class MySQLDAO {
  String MYSQL_DRIVER_CLASS="com.mysql.jdbc.Driver";
  String MYSQL_CONNECTION_STRING="jdbc:mysql://192.168.1.79:3306/tiendita";
  String MYSQL_USER="root";
  String MYSQL_PASS="root";

  protected Connection con;
  protected PreparedStatement ps;
  protected ResultSet rs;

    public Connection getConnection() throws SQLException{
        try {
            Class.forName(MYSQL_DRIVER_CLASS).newInstance();
            con = DriverManager.getConnection(MYSQL_CONNECTION_STRING,MYSQL_USER,MYSQL_PASS);
        } catch (Exception ex) {
            throw new SQLException(ex.getMessage());
        }
        return con;
    }

    public void closeConnection() throws SQLException{

            if(rs != null) {
                try { rs.close(); } catch (Exception e) { e.printStackTrace(); }
            }
            if(ps != null) {
                try { ps.close(); } catch (Exception e) { e.printStackTrace(); }
            }
            if(con != null) {
                try { con.close(); } catch (Exception e) { e.printStackTrace(); }
            }
    }
}
